package com.bocai.freeman.utils;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.bocai.freeman.R;

/**
 * Created by win7 on 2016/5/23.
 */
public class DialogHelper {

    public static AlertDialog commonDialog(Context context, String message, String commitStr, String cancelStr
            , OnLitener onLitener) {

        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_view_common, null);
        AlertDialog dialog = new AlertDialog.Builder(context).setView(dialogView).create();
        TextView tvMessage = (TextView) dialogView.findViewById(R.id.tv_message);
        TextView tvCancel = (TextView) dialogView.findViewById(R.id.tv_cancel);
        TextView tvConfirm= (TextView) dialogView.findViewById(R.id.tv_confirm);
        tvMessage.setText(message);
        tvCancel.setText(cancelStr);
        tvConfirm.setText(commitStr);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onLitener.onCancel(dialog, tvCancel);
            }
        });
        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onLitener.onConfirm(dialog, tvConfirm);
            }
        });

        return dialog;
    }

    public static AlertDialog cancelOrderDialog(Context context, OnLitener onLitener) {
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_cancel_order, null);
        AlertDialog dialog = new AlertDialog.Builder(context).setView(dialogView).create();
        TextView tvReturn = (TextView) dialogView.findViewById(R.id.tv_return);
        TextView tvConfirm = (TextView) dialogView.findViewById(R.id.tv_confirm);
        tvReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onLitener.onCancel(dialog, tvReturn);
            }
        });
        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onLitener.onConfirm(dialog, tvConfirm);
            }
        });

        return dialog;
    }

    public interface OnLitener {
        void onConfirm(AlertDialog dialog, TextView textView);

        void onCancel(AlertDialog dialog, TextView textView);
    }
}